package com.wbsxch.shiro.common;

import org.apache.shiro.crypto.RandomNumberGenerator;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

/**
 * @author: 快乐在角落里
 * @create: 2018-11-12 11:21
 */
public class ShiroUtils {

    public final static RandomNumberGenerator random = new SecureRandomNumberGenerator();

    public final static String HASH_ALGORITHM = "MD5";
    public final static Integer HASH_ITERATIONS = 2;

    /** 生成盐值 */
    public static String generateSalt(){
        return random.nextBytes().toHex();
    }

    /** 生成密码 */
    public static String generatePassword(String password,String salt){
        return new SimpleHash(HASH_ALGORITHM,password,ByteSource.Util.bytes(salt),HASH_ITERATIONS).toHex();
    }
}
